package com.dengxian.usercenter.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dengxian.usercenter.common.ErrorCode;
import com.dengxian.usercenter.exception.BusinessException;
import com.dengxian.usercenter.model.domain.Notice;
import com.dengxian.usercenter.service.NoticeService;
import com.dengxian.usercenter.mapper.NoticeMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
* @author 86151
* @description 针对表【notice(公告)】的数据库操作Service实现
* @createDate 2023-03-28 00:06:16
*/
@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice>
    implements NoticeService{

    @Override
    public void validNotice(Notice notice, boolean add) {
        if (notice == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        String content = notice.getContent();
        String title = notice.getTitle();
//        if (StringUtils.isNotBlank(content) && content.length() > 8192) {
//            throw new BusinessException(ErrorCode.PARAMS_ERROR, "内容过长");
//        }
        if (StringUtils.isNotBlank(title) && title.length() > 1024) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "标题过长");
        }
        // 创建时必须指定,所有参数必须非空
        if (add) {
            if(StringUtils.isAnyBlank(title, content)) {
                throw new BusinessException(ErrorCode.PARAMS_ERROR);
            }
        }
    }

}




